package com.sskj.tibi.ui.fragment;


import android.text.TextUtils;
import android.widget.Button;
import android.widget.EditText;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.sskj.common.base.App;
import com.sskj.common.util.ClickUtil;
import com.sskj.common.util.ToastUtil;
import com.sskj.lib.Constans;
import com.sskj.lib.RConfig;
import com.sskj.lib.base.BaseFragment;
import com.sskj.lib.bean.UserData;
import com.sskj.lib.model.room.UserViewModel;
import com.sskj.lib.util.AppCircleCheckUtil;
import com.sskj.tibi.R;
import com.sskj.tibi.R2;
import com.sskj.tibi.bean.RateBean;
import com.sskj.tibi.component.DaggerUserDataComponent;
import com.sskj.tibi.presenter.QuickBuyFragmentPresenter;

import javax.inject.Inject;

import butterknife.BindView;


/**
 * 一键买币
 */
@Route(path = RConfig.TIBI_FRAGMENT_QUICKBUY)
public class QuickBuyFragment extends BaseFragment<QuickBuyFragmentPresenter> {

    @BindView(R2.id.etUsdt)
    EditText etUsdt;
    @BindView(R2.id.btSubmit)
    Button btSubmit;
    @Inject
    UserViewModel userViewModel;
    private UserData userData;


    @Override
    protected int getLayoutId() {
        return R.layout.tibi_fragment_quick_buy;
    }

    @Override
    public QuickBuyFragmentPresenter getPresenter() {

        return new QuickBuyFragmentPresenter();
    }

    @Override
    protected void initView() {
        DaggerUserDataComponent.create().inject(this);
        ClickUtil.click(btSubmit, () -> {

            if (checkParam()) {

                mPresenter.apiRechargeOnlinerecharge(etUsdt.getText().toString());
            }
        });
    }

    private boolean checkParam() {
        if (TextUtils.isEmpty(etUsdt.getText())) {
            ToastUtil.showShort(etUsdt.getHint());
            return false;
        }
        if (Double.valueOf(etUsdt.getText().toString()) <= 0) {
            ToastUtil.showShort(App.INSTANCE.getString(R.string.tibiquickBuyFragment1));
            return false;
        }
        return true;
    }

    @Override
    protected void initData() {
        mPresenter.apiGetrate();
        userViewModel.getUsers().observe(this, users -> {
            if (users != null && users.size() > 0) {
                userData = users.get(0);
            } else {
                userData = null;
            }
        });
    }

    public void updateUI(RateBean data) {

    }

    public void onLineRecharge(String data) {
//        ARouter.getInstance().build(RConfig.APP_GUIDE_WEB).withBoolean(Constans.IS_QUICK_BUY, true).withString(Constans.URL, data).navigation();
    }
}
